<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎来到先行</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/axios.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        .el-header, .el-footer {
            background-color: white;
            color: #333;
            text-align: center;
            line-height: 60px;
        }
        .el-aside {
            background-color: #D3DCE6;
            color: #333;
            text-align: center;
            line-height: 200px;
        }

        .el-main {
            border-radius: 8px;
            text-align: center;
            line-height: 160px;
        }

        body > .el-container {
            margin-bottom: 40px;
        }

        .el-container:nth-child(5) .el-aside,
        .el-container:nth-child(6) .el-aside {
            line-height: 260px;
        }

        .el-container:nth-child(7) .el-aside {
            line-height: 320px;
        }
        html,body {
            height: 100%;
            width: 100%;
            padding: 0px;
            margin: 0px;
        }
    </style>
</head>
<body>
    <div id="app" style="height: 100%;width: 100%;">
        <el-container style="height: 100%;width: 100%;">
            <el-header style="height: 80px;line-height: 80px">
                    <img style="height: 90%;width: 200px;float: left;" src="pic/logo.png">
                    <el-link :underline="false" style="float: right;font-size: 15px;padding-left: 30px"><strong>个人中心</strong></el-link>
                    <el-link :underline="false" style="float: right;font-size: 15px;padding-left: 30px"><strong>摄影</strong></el-link>
                    <el-link :underline="false" style="float: right;font-size: 15px;padding-left: 30px"><strong>时尚</strong></el-link>
                    <el-link :underline="false" style="float: right;font-size: 15px;padding-left: 30px"><strong>生活方式</strong></el-link>
                    <el-link :underline="false" style="float: right;font-size: 15px;padding-left: 30px"><strong>主页</strong></el-link>
            </el-header>
            <el-main style="padding: 70px;background-image: url('pic/head3.jpg');background-size: 100% 100%">
                    <el-card shadow="hover" style="height: 90%;width: 300px;float: right;">
                        <el-form  >
                            <el-form-item label="用户名">
                                <el-input v-model="userForm.username"></el-input>
                            </el-form-item>
                            <el-form-item label="密码">
                                <el-input v-model="userForm.password"></el-input>
                            </el-form-item>
                            <el-button type="primary" @click="login" style="width: 100%" >登录</el-button>
                        </el-form>
                    </el-card>
                </el-image>
            </el-main>
            <el-footer>
                <div>
                    <span>关于我们</span>
                    <el-divider direction="vertical"></el-divider>
                    <span>联系我们</span>
                    <el-divider direction="vertical"></el-divider>
                    <span>开发小组</span>
                </div>
            </el-footer>
        </el-container>
    </div>
<script>
    new Vue({
        el:"#app",
        data:{
            userForm:{username:"",password:""}
        },
        methods:{
            //用户登录
            login(){
                //校验用户名密码格式是否正确
                var flag=this.checkUser();
                if(flag){
                    //执行用户登录
                    var username=this.userForm.username;
                    var password=this.userForm.password;
                    var data={"username":username,"password":password};
                    axios.post("/api/user/login",data).then(res => {
                        //成功的回调函数
                        if(res.data.flag){
                            //跳转到首页
                            window.location.href="http://127.0.0.1:80/index.html";
                        }else{
                            this.$message.error("用户名或密码错误");
                        }
                    }).catch(()=>{
                        this.$message.error("用户名或密码错误");
                    })
                }
            },
            //校验用户名与密码
            checkUser(){
                var accountPattern = /^[a-zA-Z0-9]{5,12}$/; //5-12位数字或字母
                if(!accountPattern.test(this.userForm.username)){
                    this.$message.error("用户名格式错误!");
                    return false;
                }
                if(!accountPattern.test(this.userForm.password)){
                    this.$message.error("密码格式错误!");
                    return false;
                }
                return true;
            },
            getUri(key){
                let param=location.href.split("?");
                if(param.length>1){
                    var split = param[1].split("&");
                    for(i=0;i<split.length;i++){
                        if(split[i].split("=")[0]==key){
                            return split[i].split("=")[1];
                        }
                    }
                }
                return null;
            }
        }
    })
</script>
</body>
</html>